package com.atguigu.day18.collections02;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

/**
 * @version 1.0
 * @Author 马冰
 * @Date 2024/11/22 11:35
 * @注释
 */
public class StudentTest {
    @Test
    public void test01(){
        ArrayList<Student> list = new ArrayList<>();

        Student stu1 = new Student("张三", 19, 99.5);
        Student stu2 = new Student("李四", 25, 99.7);
        Student stu3 = new Student("王五", 36, 99.8);
        Student stu4 = new Student("赵六", 19, 99.3);
        Student stu5 = new Student("孙七", 30, 99.2);

        Collections.addAll(list,stu1,stu2,stu3,stu4,stu5);

        Comparator<Student> com = new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getAge() - o2.getAge();
            }
        };
        System.out.println("----------------------年龄-------------------------------");
        Collections.sort(list,com);
        list.forEach(System.out::println);
        System.out.println("----------------------成绩------------------------");
        Collections.sort(list);
        list.forEach(System.out::println);
    }
}
